/*
 * I write in my free time, for personal using
 * when i fell proud of it, i will give it to public
 * now,have nothing more to say
 */
package com.quangtin3.tunll;

import com.quangtin3.trans.TransSender;
import com.quangtin3.msg.Channel;
import com.quangtin3.msg.Msg;
import com.quangtin3.utils.TunllException;
import com.quangtin3.utils.ControlAble;
import com.quangtin3.utils.TunllLogger;

/**
 * Receive data from Agent, pack to Msg message and
 * queue to TransSender jobs. 
 * @author quanghx
 */
public class AgentReceiver implements Runnable, ControlAble {

    private Channel channel;
    private int tunnel;
    private TransSender transSender;

    public AgentReceiver(Channel channel, int tunnel, TransSender transSender) {
        this.channel = channel;
        this.tunnel = tunnel;
        this.transSender = transSender;
    }

    public void run() {
        try {
            TunllLogger.sys.info("thread started");
            while (true) {
                Msg job = channel.receiveFromAgent(tunnel);
                TunllLogger.sys.debug("received " + job.toString());
                transSender.queue(job);
            }
        }
        catch (TunllException e) {
            TunllLogger.sys.error("exception " + e.getMessage());
        }
    }

    /**
     * close channel associated with this object and
     * stop thread running it. release all resource
     */
    public void requestStop() {

    }

    public void requestSuspend() {

    }

    public void requestResume() {

    }

    public boolean isAlive() {
        return false;
    }

    public synchronized void requestStart() {
    }
}
